package com.tg.app;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;

import com.appbase.custom.constant.CommonConstants;
import com.tange.base.toolkit.PreferenceUtil;
import com.tange.base.toolkit.StringUtils;
import com.tg.appcommon.android.TGApplicationBase;
import com.tg.appcommon.android.TGLog;
import com.tg.login.activity.ForgotPasswordActivity;
import com.tg.login.activity.LoginActivity;
import com.tange.core.backend.service.http.HttpConfigurations;
import com.tg.login.activity.RegisterActivity;
import com.tg.loginex.helper.LoginHelper;

public class MultiVersionHelper {
    public static void startRegisterActivity(Context context){
        TGLog.d(TGLog.TAG, "context ==========" + context);
        final Intent dialogIntent = new Intent(context, RegisterActivity.class);
        dialogIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
        TGApplicationBase.getApplication().startActivity(dialogIntent);
    }

    public static void startForgotPasswordActivity(Context context){
        TGLog.d(TGLog.TAG, "context ==========" + context);
        final Intent dialogIntent = new Intent(context, ForgotPasswordActivity.class);
        dialogIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
        TGApplicationBase.getApplication().startActivity(dialogIntent);
    }

    public static void startLoginActivity(Context context, String from){
        TGLog.d(TGLog.TAG, "context ==========" + context);
        final Intent dialogIntent = new Intent(context, LoginActivity.class);
        dialogIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
        if (!StringUtils.isEmpty(from)){
            dialogIntent.putExtra(LoginHelper.START_TYPE, from);
        }
        TGApplicationBase.getApplication().startActivity(dialogIntent);
    }

    public static void finishLoginActivity(){
        TGApplicationBase.getInstance().finishActivity(LoginActivity.class.getSimpleName());
    }

    public static void startLoginActivity(Activity activity){
        Intent intent = new Intent(activity, LoginActivity.class);
        activity.startActivity(intent);
    }

    public static void gotoLauncher(Activity activity, boolean thirdPartyLogout) {
        PreferenceUtil.setString(activity, CommonConstants.PRE_USER_PWD, "");
        PreferenceUtil.setInt(activity, CommonConstants.PRE_USER_ID, 0);
        PreferenceUtil.setBoolean(activity, CommonConstants.PRE_AUTO_WECHAT_LOGIN, false);
        HttpConfigurations.getInstance().setUserToken("");
        PreferenceUtil.setString(TGApplicationBase.getApplication().getBaseContext(), CommonConstants.PRE_TOKEN, "");
        TGLog.d(TGLog.TAG, "gotoLauncher");
        Intent intent = new Intent(activity, LoginActivity.class);
        intent.putExtra("thirdPartyLogout", thirdPartyLogout);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
        activity.startActivity(intent);
        activity.finish();
    }
}
